<?php

use think\migration\Migrator;

class InitCheckinData extends Migrator
{
    /**
     * 执行迁移
     */
    public function change()
    {
        // 插入默认配置
        $this->insertDefaultSettings();
        
        // 插入测试门店
        $this->insertTestStore();
        
        // 插入测试礼品
        $this->insertTestGifts();
    }
    
    /**
     * 插入默认配置
     */
    private function insertDefaultSettings()
    {
        $settings = [
            [
                'store_id' => 0,
                'key' => 'points_per_minutes',
                'value' => '10',
                'description' => '多少分钟获得1积分',
                'update_time' => date('Y-m-d H:i:s'),
            ],
            [
                'store_id' => 0,
                'key' => 'timeout_minutes',
                'value' => '480',
                'description' => '超时无效时长(分钟)，超过此时间未打结束卡则本次积分无效',
                'update_time' => date('Y-m-d H:i:s'),
            ],
            [
                'store_id' => 0,
                'key' => 'points_expire_days',
                'value' => '0',
                'description' => '积分有效期(天)，0为永久有效',
                'update_time' => date('Y-m-d H:i:s'),
            ],
            [
                'store_id' => 0,
                'key' => 'voice_start',
                'value' => '1',
                'description' => '打卡开始语音播报(1开启,0关闭)',
                'update_time' => date('Y-m-d H:i:s'),
            ],
            [
                'store_id' => 0,
                'key' => 'voice_end',
                'value' => '1',
                'description' => '打卡结束语音播报(1开启,0关闭)',
                'update_time' => date('Y-m-d H:i:s'),
            ],
        ];
        
        $this->table('checkin_setting')->insert($settings)->save();
    }
    
    /**
     * 插入测试门店
     */
    private function insertTestStore()
    {
        $stores = [
            [
                'name' => '总店',
                'code' => 'STORE001',
                'contact' => '张经理',
                'phone' => '13800138000',
                'address' => '测试地址1号',
                'status' => 1,
                'sort' => 100,
                'remark' => '总店测试数据',
                'create_time' => date('Y-m-d H:i:s'),
                'update_time' => date('Y-m-d H:i:s'),
            ],
            [
                'name' => '分店A',
                'code' => 'STORE002',
                'contact' => '李经理',
                'phone' => '13800138001',
                'address' => '测试地址2号',
                'status' => 1,
                'sort' => 90,
                'remark' => '分店A测试数据',
                'create_time' => date('Y-m-d H:i:s'),
                'update_time' => date('Y-m-d H:i:s'),
            ],
        ];
        
        $this->table('checkin_store')->insert($stores)->save();
    }
    
    /**
     * 插入测试礼品
     */
    private function insertTestGifts()
    {
        $gifts = [
            [
                'name' => '保温杯',
                'type' => '日用品',
                'points_required' => 100,
                'stock' => 50,
                'image' => '',
                'description' => '高品质保温杯，保温效果好',
                'sort' => 100,
                'status' => 1,
                'create_time' => date('Y-m-d H:i:s'),
                'update_time' => date('Y-m-d H:i:s'),
            ],
            [
                'name' => '电饭煲',
                'type' => '家电',
                'points_required' => 300,
                'stock' => 20,
                'image' => '',
                'description' => '智能电饭煲，3L容量',
                'sort' => 90,
                'status' => 1,
                'create_time' => date('Y-m-d H:i:s'),
                'update_time' => date('Y-m-d H:i:s'),
            ],
            [
                'name' => '按摩椅',
                'type' => '家电',
                'points_required' => 500,
                'stock' => 5,
                'image' => '',
                'description' => '全身按摩椅，多种按摩模式',
                'sort' => 80,
                'status' => 1,
                'create_time' => date('Y-m-d H:i:s'),
                'update_time' => date('Y-m-d H:i:s'),
            ],
        ];
        
        $this->table('checkin_gift')->insert($gifts)->save();
    }
}

